package com.tianyuan.dplrf.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;

import com.hjq.base.BaseAdapter;
import com.tianyuan.dplrf.R;
import com.tianyuan.dplrf.app.AppAdapter;
import com.tianyuan.dplrf.ui.bean.NcjtzhongmBean;
import com.xuexiang.xutil.display.DensityUtils;

public class NcjtZmAdapter extends AppAdapter<NcjtzhongmBean> {

    int withDim;
    public NcjtZmAdapter(@NonNull Context context) {
        super(context);
        withDim = (DensityUtils.getScreenWidth()/3 - DensityUtils.dip2px(12))/2;
    }


    @NonNull
    @Override
    public BaseAdapter<?>.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolde();
    }

    private final class ViewHolde extends ViewHolder{
        private AppCompatImageView img;
        private TextView tv;

        public ViewHolde() {
            super(R.layout.item_ncjt_zmlayout);
            img = getItemView().findViewById(R.id.img);
            tv = getItemView().findViewById(R.id.tv);
        }

        @Override
        public void onBindView(int position) {
            img.setLayoutParams(new LinearLayout.LayoutParams(withDim, withDim));
            img.setImageResource(getItem(position).getImgid());
            tv.setText(getItem(position).getName());
        }

    }
}
